package com.manong.bookstore.order.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.manong.bookstore.order.entity.OrderDetailEntity;
import com.manong.bookstore.order.service.OrderDetailService;
import com.manong.common.utils.PageUtils;
import com.manong.common.utils.R;



/**
 * 
 *
 * @author cyq
 * @email 465447222@qq.com
 * @date 2021-01-26  21:37:15
 */
@RestController
@RequestMapping("order/orderdetail")
public class OrderDetailController {
    @Autowired
    private OrderDetailService orderDetailService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = orderDetailService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 列表根据订单id查询列表
     */
    @RequestMapping("/listByOrderId/{orderId}")
    public R listByOrderId(@RequestParam Map<String, Object> params,@PathVariable("orderId") Integer orderId){
        PageUtils page = orderDetailService.queryPage(params,orderId);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{orderDetailId}")
    public R info(@PathVariable("orderDetailId") Integer orderDetailId){
		OrderDetailEntity orderDetail = orderDetailService.getById(orderDetailId);

        return R.ok().put("orderDetail", orderDetail);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody OrderDetailEntity orderDetail){
		orderDetailService.save(orderDetail);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody OrderDetailEntity orderDetail){
		orderDetailService.updateById(orderDetail);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] orderDetailIds){
		orderDetailService.removeByIds(Arrays.asList(orderDetailIds));

        return R.ok();
    }

}
